//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.jxwifi.cloud.quickclean.utils;


import android.util.Log;

import com.idroid.utils.CacheTool.MD5Util;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;


public class SignUtils {

    public SignUtils() {
    }

    /**
     * @deprecated
     */
    @Deprecated
    public static String createSign(Map<String, String> params, String signKey) {
        return createSign(params, "MD5", signKey, new String[0]);
    }


    public static String createSign(Map<String, String> params, String signType, String signKey, String[] ignoredParams) {
        SortedMap<String, String> sortedMap = new TreeMap(params);
        StringBuilder toSign = new StringBuilder();
        Iterator var6 = sortedMap.keySet().iterator();

        while (var6.hasNext()) {
            String key = (String) var6.next();
            String value = (String) params.get(key);
            boolean shouldSign = false;
            if (StringUtils.isNotEmpty(value) && !ArrayUtils.contains(ignoredParams, key) && !Arrays.asList(new String[]{"sign", "key", "xmlString", "xmlDoc", "couponList"}).contains(key)) {
                shouldSign = true;
            }

            if (shouldSign) {
                toSign.append(key).append("=").append(value).append("&");
            }
        }

        toSign.append("key=").append(signKey);
        System.out.println(toSign);
        Log.w("LoginWX", "WX toSign  " + toSign);
        return MD5Util.getMD5(toSign.toString()).toUpperCase();
    }


    public static boolean checkSign(Map<String, String> params, String signType, String signKey) {
        String sign = createSign(params, signType, signKey, new String[0]);
        return sign.equals(params.get("sign"));
    }

}
